/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.plant.action;

import javax.servlet.http.HttpServletRequest;

/**
 *author JAVA工程师--李琦
 * 
 * 
 * 
 */
public class GetIp {                                                              //----获取ip的方法
                public String getIp2(HttpServletRequest request) {
                    String ip = request.getHeader("x-forwarded-for");
                    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
                        ip = request.getHeader("Proxy-Client-IP");
                    }
                    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
                        ip = request.getHeader("WL-Proxy-Client-IP");
                    }
                    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
                        ip = request.getRemoteAddr();
                    }
                    return ip.equals("0:0:0:0:0:0:0:1")?"127.0.0.1":ip;
        }
                public static String getip(HttpServletRequest request) {
                	String ip = request.getHeader("x-forwarded-for");
                	if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
                		ip = request.getHeader("Proxy-Client-IP");
                	}
                	if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
                		ip = request.getHeader("WL-Proxy-Client-IP");
                	}
                	if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
                		ip = request.getRemoteAddr();
                	}
                	return ip.equals("0:0:0:0:0:0:0:1")?"127.0.0.1":ip;
                }
}
